package com.ziyueyuwen.xiniao.handler;

import com.alibaba.fastjson.JSON;
import com.ziyueyuwen.xiniao.bean.homework.HomeworkMarkData;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author jun 2018/12/4
 */
public class HomeworkMarkDataHandler extends BaseTypeHandler<HomeworkMarkData> {
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, HomeworkMarkData list, JdbcType jdbcType) throws SQLException {
        preparedStatement.setString(i, JSON.toJSONString(list));
    }

    @Override
    public HomeworkMarkData getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return JSON.parseObject(resultSet.getString(s), HomeworkMarkData.class);
    }

    @Override
    public HomeworkMarkData getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return JSON.parseObject(resultSet.getString(i), HomeworkMarkData.class);
    }

    @Override
    public HomeworkMarkData getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return JSON.parseObject(callableStatement.getString(i), HomeworkMarkData.class);
    }
}
